/**
 * @ author kunnisser
 * @ date 2018/3/14
 * @ description: 设置mock数据接口
*/

import Axios from 'axios'
import {MOCK_PATH, ACTIVE_MOCK_PATH} from '../utils/dispatchEnv'
import qs from 'qs';

const TIMEOUT = 14e3;

const getMock = (url) => {
  return (params) => Axios.get(url, {
    params,
    timeout: TIMEOUT
  })
};

const postMock = (url) => {
  return (params) => {
    let newParams = qs.stringify(params);
    return Axios.post(url, newParams, {
      timeout: TIMEOUT,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    })
  }
};

const deleteMock = (url) => {
  return (id, params) => Axios.delete(url + '/' + id, {
    params: params,
    timeout: TIMEOUT
  })
};

const putMock = (url) => {
  return params => Axios.put(url, params)
};

const patchMock = (url) => {
  return (id, params) => Axios.patch(url + '/' + id, params, {
    timeout: TIMEOUT
  })
};

const getChargeRank = getMock(MOCK_PATH + '/stubGroup/compatibleCarList');
const getInvoiceInfo = getMock(MOCK_PATH + '/invoice/fillInvoiceInfoNew');
const getUserAddress = getMock(MOCK_PATH + '/invoice/userAddressDetail');
const subInvoiceOrder = postMock(MOCK_PATH + '/invoice/generateInvoiceOrderAndBillApply');
const getBillInfo = getMock(MOCK_PATH + '/invoice/billInfo');
// 获取开放时间详情
const openTimeDetail = getMock(MOCK_PATH + '/privateStub/shareTime');
// 常见问题
const getServiceIssue = getMock(MOCK_PATH + '/serviceIssue/list');
// 评论列表
const cmdList = getMock(MOCK_PATH + '/stubGroup/commentListNew');
// 获取桩群详情列表
const sgDetailNew = getMock(MOCK_PATH + '/stubGroup/stubGroupDetailNew');
// 优享卡信息
const shareCard = getMock(MOCK_PATH + '/voucher/type/list');
// 获取电池残值x信息
const getBatteryInfo = getMock(MOCK_PATH + '/carBatteryInfo/get');
// 提交电池残值信息
const requestBatteryInfo = getMock(MOCK_PATH + '/carBatteryInfo/save');

/* 828 活动接口 */
// 获取828活动数据
const getActivityInfo = postMock(ACTIVE_MOCK_PATH + '/activityInfo/get');
// 用户抽奖接口
const lottery = postMock(ACTIVE_MOCK_PATH + '/activityLottery/lottery');
// 用户点灯操作
const requestLight = postMock(ACTIVE_MOCK_PATH + '/userLight/light');
// 获取用户抽奖后的抽奖信息
const getPrizeInfo = postMock(ACTIVE_MOCK_PATH + '/activityLottery/info/qry');
// 获取抵用券信息
const getCoupons = postMock(ACTIVE_MOCK_PATH + '/voucher/list/qry');
// 编辑地址
const editAddress = postMock(ACTIVE_MOCK_PATH + '/activityLottery/mailAddress/update');

export {
  getChargeRank,
  getInvoiceInfo,
  getUserAddress,
  subInvoiceOrder,
  getBillInfo,
  getActivityInfo,
  lottery,
  requestLight,
  getPrizeInfo,
  getCoupons,
  editAddress,
  openTimeDetail,
  cmdList,
  getServiceIssue,
  sgDetailNew,
  shareCard,
  getBatteryInfo,
  requestBatteryInfo
}
